package 电子科技大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 南京理工大学.NJuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DZU {
    public static void main(String[] args) throws IOException {
        DZUBean dzuBean = null;
        List<DZUBean> dzuBeans = new ArrayList<>();
        Connection connect = Jsoup.connect("https://www.smee.uestc.edu.cn/tagshow.jsp?urltype=tree.TreeTempUrl&wbtreeid=1177");
        Document post = connect.post();
        for (Element element : post.getElementsByTag("h2")) {
            dzuBean = new DZUBean();
            String attr = element.getElementsByTag("a").attr("href");
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);
        }

        Connection connect1 = Jsoup.connect("https://faculty.uestc.edu.cn/xylb.jsp?totalpage=6&PAGENUM=2&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN");
        Document post1 = connect1.post();
        for (Element element : post1.getElementsByTag("h2")) {
            dzuBean = new DZUBean();

            String attr = element.getElementsByTag("a").attr("href");
//            System.out.println(element.getElementsByTag("a").text());
//            System.out.println(attr);
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);

        }
        Connection connect2 = Jsoup.connect("https://faculty.uestc.edu.cn/xylb.jsp?totalpage=6&PAGENUM=3&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN");
        Document post2 = connect2.post();
        for (Element element : post2.getElementsByTag("h2")) {
            dzuBean = new DZUBean();

            String attr = element.getElementsByTag("a").attr("href");
//            System.out.println(element.getElementsByTag("a").text());
//            System.out.println(attr);
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);

        }
        Connection connect3 = Jsoup.connect("https://faculty.uestc.edu.cn/xylb.jsp?totalpage=6&PAGENUM=4&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN");
        Document post3 = connect3.post();
        for (Element element : post3.getElementsByTag("h2")) {
            dzuBean = new DZUBean();

            String attr = element.getElementsByTag("a").attr("href");
//            System.out.println(element.getElementsByTag("a").text());
//            System.out.println(attr);
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);

        }
        Connection connect4 = Jsoup.connect("https://faculty.uestc.edu.cn/xylb.jsp?totalpage=6&PAGENUM=5&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN/xylb.jsp?urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN#collegeteacher");
        Document post4 = connect4.post();
        for (Element element : post4.getElementsByTag("h2")) {
            dzuBean = new DZUBean();

            String attr = element.getElementsByTag("a").attr("href");
//            System.out.println(element.getElementsByTag("a").text());
//            System.out.println(attr);
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);

        }
        Connection connect5 = Jsoup.connect("https://faculty.uestc.edu.cn/xylb.jsp?totalpage=6&PAGENUM=6&urltype=tsites.CollegeTeacherList&wbtreeid=1021&st=0&id=2035&lang=zh_CN");
        Document post5 = connect5.post();
        for (Element element : post5.getElementsByTag("h2")) {
            dzuBean = new DZUBean();

            String attr = element.getElementsByTag("a").attr("href");
//            System.out.println(element.getElementsByTag("a").text());
//            System.out.println(attr);
            dzuBean.setUrl(attr);
            dzuBean.setT_name(element.getElementsByTag("a").text());
            dzuBeans.add(dzuBean);

        }
        for (DZUBean bean : dzuBeans) {
            System.out.println(bean);
        }
        EasyExcel.write("src/DZu.xlsx", DZUBean.class).sheet("user").doWrite(dzuBeans);

    }
}
